package com.three.Controller;

import com.github.pagehelper.PageInfo;
import com.three.Pojo.Student;
import com.three.Service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private IStudentService studentService;
    @RequestMapping("/tostudent.do")
    public  String tostudent(ModelMap map, String stuName,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize){
        PageInfo<Student> pagelist=studentService.findlist(pageNum,pageSize,stuName);
        map.addAttribute("pagelist",pagelist);
        map.addAttribute("stuName",stuName);
        return "student";
    }

    @RequestMapping("/toadd.do")
    public String toadd(){
        return "studentAdd";
    }

    @RequestMapping("/addsave.do")
    public  String addsave(Student student){
        studentService.addsave(student);
        return "redirect:/student/tostudent.do";
    }

    @RequestMapping("/promodify.do")
    public  String promodify(ModelMap map,Integer Id){
        Student student=studentService.findByid(Id);
        map.addAttribute("student",student);
        return "studentUpdate";
    }

    @RequestMapping("/updatesave")
    public  String updatesave(Student student){
        studentService.updatesave(student);
        return "redirect:/student/tostudent.do";
    }

    @RequestMapping("/delete.do")
    public String delete(Integer Id){
        studentService.delete(Id);
        return  "redirect:/student/tostudent.do";
    }


}
